//
//  UINavigationBar+extension.m
//  sample
//
//  Created by sunshaobei on 2021/12/16.
//

#import "UINavigationBar+extension.h"
#import "UIImage+extension.h"

@implementation UINavigationBar (extension)

-(void) withStatusBarColor:(UIColor *)color andTitleColor:(nonnull UIColor *)titleColor{
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    [attributes setValue:titleColor forKey:NSForegroundColorAttributeName];
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        [appearance configureWithOpaqueBackground];
        //设置导航条背景色
        appearance.backgroundColor = color;
        appearance.shadowColor = UIColor.clearColor;
        appearance.shadowImage = [UIImage imageWithColor:UIColor.clearColor];
        //设置导航条标题颜色
        appearance.titleTextAttributes = attributes;
        self.standardAppearance = appearance;
        self.scrollEdgeAppearance = self.standardAppearance;
    }else{
        //设置导航条标题颜色
        self.titleTextAttributes = attributes;
        [self setShadowImage:[UIImage new]];
        UIImage *navBgImg = [[UIImage imageWithColor:UIColor.redColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [self setBackgroundImage:navBgImg forBarMetrics:UIBarMetricsDefault];
    }
    //透明设置
    self.translucent = NO;
    //navigationItem控件的颜色
    self.tintColor = [UIColor whiteColor];

}
@end
